﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Model.Sadharon;
using Model.Poribar;
using Model.Sohaok;
using Model.Poribar.ProductPanjeri;
using Model.Poribar.ColourPanjeri;
using Model.Poribar.SizePanjeri;
using Model.Panjeri;
using Model.Upadan;

namespace InventorySys.controller
{
    public class ProductController
    {

        private ProductKaz productRow;
        private ColourKaz colorRow;
        private SizeKaz sizeRow;
        private Result result;
        private Product product;
        private ProductSize size;
        private ProductColor color;
        public ProductController() {
            productRow = Panjeri.getProductPanjeri();
            colorRow = Panjeri.getColourPanjeri();
            sizeRow = Panjeri.getSizePanjeri();
            result = new Result();
        }


        public Result addNewProduct(Object productObj) {
            product = (Product)productObj;
            size = (ProductSize)sizeRow.getByName(product.Size).ResultObj;
            color = (ProductColor)colorRow.getByName(product.Colour).ResultObj;
            product.Size = size.Id;
            product.Colour = color.Id;
            return productRow.create(product);
        }

        public Result GetAllProducts() {
            List<Product> allProducts = new List<Product>();
            result =  productRow.All();
            foreach (Product _product in (List<Product>)result.ResultObj) {
                size = (ProductSize)sizeRow.getById(_product.Size).ResultObj;
                color = (ProductColor)colorRow.getById(_product.Colour).ResultObj;
                _product.Colour = color.Name;
                _product.Size = size.Name;
                allProducts.Add(_product);
            }
            result.ResultObj = allProducts;
            return result;
        }
    }
}
